<?php
/**
 * 没有任何逻辑的Model类
 * @author blues
 */
namespace App\Models\User;
use App\Models\Common\CommonUser;
use Larfree\Models\Api;
use App\Scopes\User\UserHistoryScope;
class UserHistory extends Api
{
    use UserHistoryScope;


    public  function logUserHistory($newsId){
        $user=CommonUser::getUserInfo();
        if($user){
            $data=[
                'history_id'=>$newsId,
                'user_id'=>getLoginUserID(),
                'created_at'=>date('Y-m-d H:i:s',strtotime(now()))
            ];
            $check=UserHistory::query()->where('history_id',$newsId)->where('user_id',getLoginUserID())->first();
            if($check){
                $check->updated_at=date('Y-m-d H:i:s',strtotime(now()));
                $check->save();
            }else{
                UserHistory::query()->insert($data);
            }
        }


    }

}